<template>
    <div class="news" >
        <router-link 
            :to="{path:'/detail',
            query:{ //params
                    id:list1.id,
                }}">
            <div class="first" :class="{'act':list1.type !== '推荐'}">
                <div class="fir_left" >
                    <h4>{{list1.title}}</h4>
                    <div class="p">{{list1.desc}}</div>
                    <span>立即查看</span>
                </div>
                <div class="fir_right">
                    <img :src="list1.url" alt="">
                </div>
            </div>
        </router-link>
        <div class="type">{{this.$route.query.type || '推荐'}}</div>
        <div class="goods" >
            <ul>
                <li v-for="item in list" :key="item.id" :class="{'act':list1.type !== '推荐'}">
                    <router-link 
                    :to="{path:'/detail',
                    query:{ //params
                            id:item.id,
                        }}">
                    <img :src="item.url" alt="">
                    <div class="goods_r">
                        <div><p>{{item.title}}</p></div>
                        <div><p>￥{{item.price}}</p></div>
                    </div>
                    </router-link>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    name:'news',
    props:['id','type'],
    data() {
        return {
            list:[],
            list1:[],
        }
    },
    mounted() {
        let type = this.$route.query.type || '推荐'
        axios.get(`http://localhost:3000/xiaomi?type=${type}`).then(
            response => {
                this.list = response.data.list
                this.list1 = this.list.splice(0,1)[0]
            },
            error =>{
                console.log('失败');
            }
        )
  },
}
</script>
<style scoped>
    ul{
        text-align: center;
    }
    .news {
        width: 10.506rem;
        margin: 2rem 0 0 3.8rem;
    }
    .first {
        display: flex;
        justify-content: space-between;
        width: 10.2rem;
        height: 3.04rem;
        background-color: #f6f6f6;
        border-radius:.4rem;
        overflow: hidden;
    }
    .fir_left {
        padding-left: .48rem;
        padding-top: .32rem;
    }
    .fir_left h4 {
        color: #666;
        margin-bottom: .1rem;
    }
    .fir_left .p {
       width: 6.92rem;
       height: .62rem;
       overflow: hidden;
       color: #999;
       margin-bottom: .22rem;
    }
    .fir_left span {
        text-decoration: none;
        border: .04rem solid #333;
        color: #333;
        font-size: .1rem;
    }
    .fir_right img {
        padding-top: .12rem;
        width: 2.8rem;
        height: 2.8rem;
    }
    .type {
        font-size: .6rem;
        color: #333;
        font-weight: 700;
        margin: .6rem 0 .2rem 0;
    }
    .goods {
        padding-bottom: 1.8rem;
    }
    .goods ul li {
        display: flex;
        border-radius: .2rem;
        margin-bottom: .4rem;
        
        background-color: #f6f6f6;
    }
    .act {
        background-color: #fff !important;
    }
    .goods ul li a {
        display: flex;
        width: 100%;
    }
    .goods ul li img {
        width: 2.8rem;
        height: 2.8rem;
        margin-right: .2rem;
        padding-top: .12rem;
    }
    .goods_r {
        font-size: .6rem;
        color: #333;
        margin: .4rem 0 0 .2rem;
    }
    .goods_r div {
        width: 7.2rem;
        height: 1rem;
        overflow: hidden;
        text-align: left;
    }
    .goods_r p:last-child{
        margin-top: .2rem;
    }
</style>